package band.wukong.practice.webservice.kh.sample01.nongen;

import band.wukong.practice.webservice.kh.sample01.SomebodyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.Test;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * 直接用server api，不好的方法
 * 无法做到跨平台、环境无关。client必须知道服务的API。必须知道这个SomebodyService接口。
 *
 * @author wukong(wukonggg@139.com)
 */
public class SomebodyClientByServerAPI {

    private static final Logger logger = LoggerFactory.getLogger(SomebodyClientByServerAPI.class);

    @Test
    public void sing() throws MalformedURLException {
        final String words = "我不能悲伤地坐在你身旁";

        URL url = new URL(SomebodyConst.SERVICE_WSDL);
        QName qName = new QName(SomebodyConst.SERVICE_NS, SomebodyConst.SERVICE_NAME);
        Service service = Service.create(url, qName);
        SomebodyService port = service.getPort(SomebodyService.class);
        String ret = port.sing(words);
        logger.info(ret);

        Assert.assertEquals(ret, words);
    }

}
